<template>
    <el-dropdown class=" g-flex-align-cross-center" @command="handleUserinfoCommand"
                 v-loading="userinfoLoading"
                 element-loading-spinner="el-icon-loading">
        <div class="st-pointer  st-color-fff st-flex-align-cross-center"  style="padding: 0 5px;">
            <el-avatar icon="el-icon-user-solid" :src="avatar"></el-avatar>
            <span style="margin-left: 5px;"> {{nickname}}</span>
        </div>
        <el-dropdown-menu slot="dropdown">
            <!--<el-dropdown-item command="userinfo">个人信息</el-dropdown-item>
            <el-dropdown-item  command="updatePwd">修改密码</el-dropdown-item>
            <el-dropdown-item command="userinfoEdit">修改信息</el-dropdown-item>-->
            <el-dropdown-item  command="logout">退出登陆</el-dropdown-item>
        </el-dropdown-menu>
    </el-dropdown>
</template>

<script>
    export default {
        components: {
        },
        props:{
            userinfoLoading:{
                type:Boolean,
                default: false
            },
            currentUserinfo:{
                type:Object,
                default: null
            }
        },
        computed: {
            nickname(){
                let r = ''
                if(this.currentUserinfo){
                    r = this.currentUserinfo.nickname || this.currentUserinfo.username
                }
                return r
            },
            avatar(){
                let r = ''
                if(this.currentUserinfo){
                    r = this.currentUserinfo.avatar
                }
                return r
            }
        },
        data (){
            return {
            }
        },
        mounted(){
        },
        methods:{
            handleUserinfoCommand(command){
                switch (command) {
                    case 'userinfo':{

                        this.$router.push('/base/user/userinfo/current')
                        break
                    }
                    case 'updatePwd':{

                        this.$router.push('/base/user/updatePwd')
                        break
                    }
                    case 'userinfoEdit':{
                        this.$router.push('/base/user/userinfoEdit/current')
                        break
                    }
                    case 'logout':{
                        // jwt退出不需要调用接口，废弃token就可以了
                        this.axios.post('/logout')
                        // 如果不是向前端
                        this.$router.replace('/login')
                        break
                    }
                }
            },
        },
        watch: {
        }
    }
</script>

<style scoped>

</style>